package cn.wolfcode._04hello;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 *  消息  SQL过滤
 *
 */
// 生产者 -----
public class Producer {
    // 延时消息 -----------------------------------------------
    public static void main(String[] args) throws Exception {
        // 实例化消息生产者Producer
        DefaultMQProducer producer = new DefaultMQProducer("wolfcode_producer-sql");
        // 设置NameServer的地址
        producer.setNamesrvAddr("192.168.204.128:9876"); // 注意修改为服务所在的电脑ip
        // 启动Producer实例
        producer.start();
        // 创建消息，并指定Topic，Tag和消息体
        Message msg1 = new Message("sqlFilterTopic", ("美女A").getBytes());
        msg1.putUserProperty("age", "18");
        msg1.putUserProperty("weight", "45");
        Message msg2 = new Message("sqlFilterTopic", ("美女B").getBytes());
        msg1.putUserProperty("age", "28");
        msg1.putUserProperty("weight", "60");
        Message msg3 = new Message("sqlFilterTopic", ("美女C").getBytes());
        msg1.putUserProperty("age", "38");
        msg1.putUserProperty("weight", "80");
        // 设置延时级别

        // 发送消息到一个Broker,返回发送结果
        SendResult sendResult1 = producer.send(msg1);
        producer.send(msg2);
        producer.send(msg3);
        // 通过sendResult返回消息是否成功送达
        System.out.println(sendResult1);
        // 如果不再发送消息，关闭Producer实例。
        System.out.println("消息发送完成");
        producer.shutdown();
    }


}